package com.pet_service.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pet_service.entity.HomeServiceType;
import com.pet_service.mapper.HomeServiceTypeMapper;
import com.pet_service.result.Result;
import com.pet_service.service.HomeServiceTypeService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 邹全伸
* @description 针对表【home_service_type(上门服务类型表)】的数据库操作Service实现
* @createDate 2025-09-20 09:18:18
*/
@Service
public class HomeServiceTypeServiceImpl extends ServiceImpl<HomeServiceTypeMapper, HomeServiceType>
    implements HomeServiceTypeService {

    @Resource
    private HomeServiceTypeMapper homeServiceTypeMapper;

    // 实现物理删除：调用Mapper的自定义方法
    @Override
    public boolean physicalDelete(Integer id) {
        // 执行自定义删除SQL，返回影响行数（1表示成功，0表示失败）
        int rows = baseMapper.deleteByPhysicalId(id);
        return rows > 0;
    }

    //根据订单id和服务类型id查询上门服务的订单
    @Override
    public Result setOrderIdAndServiceId(Integer order_id, Integer service_type_id) {
        //
        if (order_id == null || order_id <= 0) {
            return Result.fail("订单id错误");
        }
        if (service_type_id == null || service_type_id <= 0) {
            return Result.fail("服务类型id错误");
        }
        List<HomeServiceType> homeServiceTypes = homeServiceTypeMapper.selectByOrderIdAndServiceTypeId(order_id, service_type_id);
        if (homeServiceTypes != null && homeServiceTypes.size() > 0) {
            return Result.ok(homeServiceTypes);
        }
        return Result.fail("没有查询到数据");
    }
}




